home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / SOUND / MP3CONV.ZIP / !MP3Conv / c / sound-vox < prev    next >
Text File  |  1997-04-05  |  2KB  |  75 lines

  1. #if defined(__FreeBSD__)
  2. # include <machine/soundcard.h>
  3. #else
  4. # include <sys/soundcard.h>
  5. #endif
  6. #include <sys/ioctl.h>
  7. #include "common.h"
  8. #include "sound.h"
  9.  
  10. /*
  11.  * Sound-specific stuff for VOXware compatible audio devices.
  12.  */
  13.  
  14. int sound_init(int audiofd, layer *info, int stereo) {
  15.     int        samplefrq = (int)
  16.             (s_freq[info->version]
  17.             [info->sampling_frequency] * 1000.0);
  18.     int        tmp;
  19.  
  20.     /* Sample size/precision? */
  21.     tmp = AFMT_S16_LE;
  22.     if (ioctl(audiofd, SNDCTL_DSP_SETFMT, &tmp) == -1) {
  23.     perror("SNDCTL_DSP_SETFMT");
  24.     return(1);
  25.     }
  26.     if (tmp != AFMT_S16_LE) {
  27.     perror("Soundcard doesn't support 16 bit sound!");
  28.     return(1);
  29.     }
  30.  
  31.     /* Mono/stereo */
  32.     tmp = stereo;
  33. #if defined(__FreeBSD__)
  34. #define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
  35. #endif
  36.     if (ioctl(audiofd, SNDCTL_DSP_CHANNELS, &tmp) == -1) {
  37.     perror("SNDCTL_DSP_CHANNELS");
  38.     return(1);
  39.     }
  40.  
  41.     /*
  42.      * Frequency, this has to be set after the number of channels
  43.      * is selected otherwise SBPros fuck up
  44.      */
  45.     if (ioctl(audiofd, SNDCTL_DSP_SPEED, &samplefrq) == -1) {
  46.     perror("SNDCTL_DSP_SPEED");
  47.     return(1);
  48.     }
  49.  
  50.     /*
  51.      * Improves transport of sample data to audio device
  52.      */
  53.     tmp=12;
  54.     ioctl(audiofd, SNDCTL_DSP_SETFRAGMENT, &tmp);
  55.      /*
  56.       * Raise the priority of audio device operations. This
  57.       * only works if mpeg3play runs as root.
  58.       */
  59.     nice(-11);
  60.  
  61.     return(0);
  62. }
  63.  
  64. int sound_open() {
  65.     return(open("/dev/dsp", O_WRONLY));
  66. }
  67.  
  68. int sound_close(int audiofd) {
  69.     return(close(audiofd));
  70. }
  71.  
  72. int sound_write(int audiofd, const void *buffer, size_t count) {
  73.     return(write(audiofd, buffer, count));
  74. }
  75.